package remin;

import java.sql.ResultSet;
import java.sql.Statement;

public class DelUp {
	
	int r;
	Object delid;
	Refr ref = new Refr();
	
	public void idRow(){
	r = RemGui.tabulka.getSelectedRow();
	delid = RemGui.tabulka.getValueAt(r, 0);
	//System.out.println("Riadok: "+r);
	//System.out.println(delid);
	}
			
	public void delrow(){
	String delque = "delete from reminder where idrem = " + delid;
	try{
		System.out.println(delque);
		Statement s = DBCon.conn.createStatement();
        s.executeUpdate(delque);
        ref.refr();
      //tu bol refresh udalosti
        RemGui.comm.setText("Uspesne vymazane...");
	}catch(Exception e){
		RemGui.comm.setText("Nepodarilo sa vymazat...");
	}
	}
	public void napUF(){
		UpFor upr = new UpFor();
		try{
			//naplnenie okna update formularu
	        Statement u = DBCon.conn.createStatement();
	           u.executeQuery("select * from reminder where idrem ="+ delid);
	           ResultSet us = u.getResultSet();
	           while(us.next()){
	          	 
	           String priorita = us.getString(4).trim();	          
	           upr.den.setText(us.getString(2).substring(8, 10));
	           upr.mesiac.setText(us.getString(2).substring(5, 7));
	           upr.rok.setText(us.getString(2).substring(2, 4));
	           upr.hod.setText(us.getString(2).substring(11, 13));
	           upr.min.setText(us.getString(2).substring(14, 16));
	           upr.pret.setText(us.getString(3));
	           upr.priot.setSelectedItem(priorita);
	           upr.pozt.setText(us.getString(5));
	          	 
	           break;
	           }
			}catch(Exception e){
				RemGui.comm.setText("Nieco nie je v poriadku...");
			}
	}
	public void upRow(String updat){
		//update reminder set datum_cas = TO_DATE('dd-mm-ro hh:mi','DD-MM-YY 
		//HH24:MI'),predmet = 'sak test',priorita='Vysoka',poznamka ='poznamocky
		//sem' where idrem = 1

		String upque = updat + delid;
		//System.out.println(upque);
		try{
			
			Statement s = DBCon.conn.createStatement();
	        s.executeUpdate(upque);
	        ref.refr();
	        RemGui.comm.setText("Uspesne upravene...");
		}catch(Exception e){
			RemGui.comm.setText("Nepodarilo sa upravit...");
		}
		
	}
}
